#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Utilities.Miscellaneous;
using Utilities.Testing;
using Utilities.Text;

namespace Utilities.Test.Text
{
  public class FormatUtilsFixture : TestFixtureBase
  {
    [Test]
    public void FileSizeToString()
    {
      long fileSize;
      string result;

      fileSize = 532;
      result = FormatUtils.FileSizeToString(fileSize);
      Assert.AreEqual("532 bytes", result);

      fileSize = 1240;
      result = FormatUtils.FileSizeToString(fileSize);
      Assert.AreEqual("1.21 KB", result);

      fileSize = 235606;
      result = FormatUtils.FileSizeToString(fileSize);
      Assert.AreEqual("230 KB", result);

      fileSize = 5400016;
      result = FormatUtils.FileSizeToString(fileSize);
      Assert.AreEqual("5.14 MB", result);

      fileSize = long.MaxValue;
      result = FormatUtils.FileSizeToString(fileSize);
      Assert.AreEqual("8,388,608 TB", result);
    }

    [Test]
    public void FileSizeToStringKB()
    {
      long fileSize;
      string result;

      fileSize = 0;
      result = FormatUtils.FileSizeToStringKB(fileSize);
      Assert.AreEqual("0 KB", result);

      fileSize = 1;
      result = FormatUtils.FileSizeToStringKB(fileSize);
      Assert.AreEqual("1 KB", result);

      fileSize = 1024;
      result = FormatUtils.FileSizeToStringKB(fileSize);
      Assert.AreEqual("1 KB", result);

      fileSize = 1025;
      result = FormatUtils.FileSizeToStringKB(fileSize);
      Assert.AreEqual("2 KB", result);

      fileSize = 9216000;
      result = FormatUtils.FileSizeToStringKB(fileSize);
      Assert.AreEqual("9,000 KB", result);

      fileSize = long.MaxValue;
      result = FormatUtils.FileSizeToStringKB(fileSize);
      Assert.AreEqual("9,007,199,254,740,990 KB", result);
    }

    [Test]
    public void GetOrdinal()
    {
      Assert.AreEqual("st", FormatUtils.GetOrdinal(1));
      Assert.AreEqual("nd", FormatUtils.GetOrdinal(2));
      Assert.AreEqual("rd", FormatUtils.GetOrdinal(3));
      Assert.AreEqual("th", FormatUtils.GetOrdinal(4));

      Assert.AreEqual("th", FormatUtils.GetOrdinal(11));
      Assert.AreEqual("th", FormatUtils.GetOrdinal(12));
      Assert.AreEqual("th", FormatUtils.GetOrdinal(13));
      Assert.AreEqual("th", FormatUtils.GetOrdinal(14));

      Assert.AreEqual("st", FormatUtils.GetOrdinal(21));
      Assert.AreEqual("nd", FormatUtils.GetOrdinal(22));
      Assert.AreEqual("rd", FormatUtils.GetOrdinal(23));
      Assert.AreEqual("th", FormatUtils.GetOrdinal(24));

      Assert.AreEqual("st", FormatUtils.GetOrdinal(101));
      Assert.AreEqual("nd", FormatUtils.GetOrdinal(102));
      Assert.AreEqual("rd", FormatUtils.GetOrdinal(103));
      Assert.AreEqual("th", FormatUtils.GetOrdinal(104));
    }
  }
}